<?php
if (!defined('IN_WONDERSHARE'))
{
die('Hacking attempt');
}
require('./classes/module/module_ad_position.php');
class AdPositionControl
{
	var $ad_position_m;
	function __construct()
	{
	
		$this->ad_position_m = new AdPositionModule();
	}

	/**
	* 增加或者修改ad_position
	*
	* @param   string      $type            操作类型
	* @param   string      array     	      
	* @param   text        $content         留言内容
	* @return  int
	*/
	function  operate_ad_position($type,$array = '',$w_type)
	{
		//调用存储过程
		$GLOBALS['db']->query("call operate_ad_position('".$array['position_id']."','".$array['position_name']."','".$array['position_size']."',
		'".$array['position_type']."','".$array['position_description']."','".$array['position_location']."','".$_SESSION['AName']."',$w_type,@last_id);");
		return array('affect_nums' => $this->ad_position_m->getOne("SELECT  @inset_num "),'last_id' =>$this->ad_position_m->getOne("SELECT  @last_id "));
	}

	/**
	* 批量删除标签
	*
	* @param   string         $list_id    id字符串
	*
	* @return  int
	*/
	function delete_ad_position($list_id)
	{
		$sql = "UPDATE ad_position SET is_delete=1  WHERE  FIND_IN_SET(position_id,'".$list_id."') ";
		return $this->ad_position_m->change_info($sql);
	}
	/**
	* 得到数据提交条件返回url参数
	* @param   int        $w_type         1为wondershare网站，2为aimersoft网站，3为anypdftools.com网站，4为applemacvideo.com网站，5为www.wondershare.jp网站，6为www.wondershare.de网站
	* @param   int        $ad_location  投放位置
	* @param   string     $ad_size    广告尺寸
	* @param   string     $ad_name    广告名称
	* @return  string
	*/
	function get_url_par($w_type,$ad_location,$ad_size,$ad_name)
	{ 
		$url_str = '&url_page=1';
		if(!empty($w_type))
		{
			$url_str.='&w_type='.$w_type;
		}
		if($ad_location!= '0|0|0')
		{
			$url_str.='&ad_location='.$ad_location;
		}
		if(!empty($ad_size))
		{
			$url_str.='&ad_size='.$ad_size;
		}
		if(!empty($ad_name))
		{
			$url_str.='&ad_name='.$ad_name;
		}
		
		return  $url_str;
	}

	/**
	* 得到分页相关信息
	*
	* @param   int        $page       页码
	* @param   int        $type       类型
	* @param   int        $w_type     网站类型
	* @param   int        $pagesize   取多少条记录
	* @return  array
	*/
	function get_url_info($page,$type,$pagesize = 10,$w_type)
	{
		if($type == 'list_index')////不带条件搜索
		{
			$sql_p = "SELECT COUNT(*) AS total FROM ad_position  WHERE   ad_web  = $w_type  AND is_delete = 0 ";
		}
		$page_info = get_page_info($sql_p,$pagesize,$page);
		$page_url = get_page_url($page,$page_info['page_num']);
		return  array('page_info'=>$page_info,'page_url'=>$page_url);
	}
	/**
	* 得到列表ad_position信息
	*
	* @param   string     $type       类型（list为列表 不带搜索 而 list_s 在列表 带有搜索）
	* @param   int        $position_id   广告位主键
	* @param   int        $start      从那行开始
	* @param   int        $pagesize   取多少条记录
	* @param   int        $w_type     网站类型
	* @return  array
	*/
	function  get_ad_position_info($type,$position_id,$w_type,$start = 0,$pagesize = 10)
	{
		$row  = array();
		
		if($type == 'list_index')//不带条件搜索
		{
			$sql = "SELECT position_id,position_name,position_size,position_description,update_user,IF(update_time > 0, 
			FROM_UNIXTIME(update_time, '%Y-%m-%d'), '') update_time FROM ad_position 
			WHERE ad_web  = $w_type  AND is_delete = 0  ORDER BY position_id DESC LIMIT $start,$pagesize ";
			$rows = $this->ad_position_m->get_ad_info($sql);
		}else if($type == 'position_edit')//根据ID得到相关信息
		{
			$sql = "SELECT position_id,position_name,position_type,position_size,position_description,position_location,update_user,IF(update_time > 0, 
			FROM_UNIXTIME(update_time, '%Y-%m-%d'), '') update_time FROM ad_position 
			WHERE position_id  = $position_id  ";
			$rows = $this->ad_position_m->get_ad_info($sql);
		}
		return $rows;
	}
	/**
	* ajax修改ad_position
	*
	* @param   int        $position_id          标签id
	* @param   string     $change_value         要修改的值
	* @param   string     $field                数据字段
	* @return  int
	*/
	function  change_info($position_id,$change_value,$field,$type)
	{
		
		if($type == 'update_name')
		{
			$sql = "UPDATE ad_position SET $field ='$change_value',update_time = '".$_SERVER['REQUEST_TIME']."',
			update_user = '".$_SESSION['AName']."'  WHERE position_id  = $position_id ";
		
		}
		
		return $this->ad_position_m->change_info($sql);
	}


}





?>